var _api = _interopRequireDefault(require("../../utils/api")), _cardUtil = _interopRequireDefault(require("../../utils/card-util"));

function _interopRequireDefault(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

Component({
    properties: {
        maskClick: {
            type: Boolean,
            value: !0
        }
    },
    data: {
        maskIndex: "100",
        uiIndex: "99",
        clickToHide: !0,
        list: [],
        corpname: "",
        isShown: !1
    },
    methods: {
        getList: function(t) {
            var e = this, a = t.corpname;
            return this.formData = Object.assign({}, t), _api.default.minicard.card.samecompanylists({
                loading: "加载中...",
                data: {
                    corpname: a
                }
            }).then(function(t) {
                return e._handleListResult(t, a);
            }).catch(function() {
                return e._onCreate();
            });
        },
        _handleListResult: function(t, e) {
            var a = t.data.list;
            if (!(a = a.filter(function(t) {
                return +t.total;
            }).map(function(t) {
                return t.colleagues = t.colleaguename.join("、"), t;
            })).length) return Promise.reject();
            wx.hideTabBar(), this.setData({
                list: a,
                corpname: e,
                isShown: !0,
                guid: a[0].guid
            }), this.status = a[0].authstatus, wx.joinSuccess && (this.onClose(), wx.joinSuccess = !1);
        },
        onMaskEvent: function(t) {
            this.data.maskEventName && this.triggerEvent(this.data.maskEventName, t, {});
        },
        _onApply: function(t) {
            var e = this, a = t.currentTarget.dataset.guid, n = this.formData;
            n.guid = a, _api.default.minicard.card.applyjoin({
                loading: "申请中...",
                data: n,
                name: "avatar",
                filePath: n.avatar
            }).then(function() {
                e.onClose(), _cardUtil.default.createSuccess(), e.triggerEvent("success", {}, {});
            });
        },
        checkIsAuthCorp: function() {
            return 1 == +this.status && (this.onClose(), wx.showModal({
                content: "该公司名称已通过认证保护，不可重复创建，请修改名称后创建",
                showCancel: !1,
                confirmText: "我知道了"
            }), !0);
        },
        _onCreate: function() {
            var t = this;
            this.checkIsAuthCorp() || _cardUtil.default.create(this.formData).then(function() {
                t.onClose(), t.triggerEvent("success", {}, {});
            });
        },
        onClose: function() {
            this.setData({
                isShown: !1
            }), wx.showTabBar();
        }
    }
});